package com.cn.hotel.service.impl;

import com.cn.hotel.dao.ICompanyContactDao;
import com.cn.hotel.dao.Impl.CompanyContactImpl;
import com.cn.hotel.model.CompanyContactModel;
import com.cn.hotel.service.ICompanyContactService;
import redis.clients.jedis.Jedis;

import java.util.List;

public class CompanyContactServiceImpl implements ICompanyContactService {
    @Override
    public List<CompanyContactModel> findAll(CompanyContactModel companyContactModel) {
        ICompanyContactDao iCompanyContactDao = new CompanyContactImpl();
        return iCompanyContactDao.findAll(companyContactModel);
    }

    /**
     *通过id查询信息 给编辑页面赋值
     * @param temp
     * @return
     */
    @Override
    public CompanyContactModel findById(Integer temp) {
        ICompanyContactDao iCompanyContactDao = new CompanyContactImpl();
        return iCompanyContactDao.findById(temp);
    }

    /**
     * 保存编辑
     * @param companyModel
     * @return
     */
    @Override
    public int edit(CompanyContactModel companyModel) {
        ICompanyContactDao iCompanyContactDao = new CompanyContactImpl();
        int result = iCompanyContactDao.edit(companyModel);
        if (result == 1) {
            Jedis jedis = new Jedis();
            jedis.del("company_phone");
//            jedis.flushAll();删除所有redis数据
//            jedis.flushDB();删除当前数据库
        }
        return result;
    }

    /**
     * 新增
     * @param companyModel
     * @return
     */
    @Override
    public int add(CompanyContactModel companyModel) {
        ICompanyContactDao iCompanyContactDao = new CompanyContactImpl();
        int result = iCompanyContactDao.add(companyModel);
        if (result == 1) {
            Jedis jedis = new Jedis();
            jedis.del("company_phone");
//            jedis.flushAll();删除所有redis数据
//            jedis.flushDB();删除当前数据库
        }
        return result;
    }

    /**
     * 获取条数
     * @param companyContactModel
     * @return
     */
    @Override
    public int getNumber(CompanyContactModel companyContactModel) {
        ICompanyContactDao iCompanyContactDao = new CompanyContactImpl();
        return iCompanyContactDao.getNumber(companyContactModel);
    }

    @Override
    public int delete(Integer temp) {
        ICompanyContactDao iCompanyContactDao = new CompanyContactImpl();
        int result = iCompanyContactDao.delete(temp);
        if (result == 1) {
            Jedis jedis = new Jedis();
            jedis.del("company_phone");
//            jedis.flushAll();删除所有redis数据
//            jedis.flushDB();删除当前数据库
        }
        return result;
    }
}
